/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vue;

/**
 *
 * @author Harakan
 */
import ecouteurs.EcouteurNotice8;
import ecouteurs.EcouteurStart;
import ia_multiagent1.Agent;
import ia_multiagent1.Espace2D;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
 
public class InterfacePrincipaleFrame extends JFrame{
 
    private int hauteurFenetre;
    private int largeurFenetre;
    private int dimGridCases;
    private int dimPixelCase = 15;
    
    
    private JSplitPane split;
    private JPanelGrid maGrille;
    private JPanelSide side;
    
    
    public InterfacePrincipaleFrame(int dimGridCases, Vector<Agent> mesAgents, Espace2D espace2d,boolean onlyValeurChamps, boolean presencePheromones){
      
        
       this.dimGridCases = dimGridCases;

       
       int tailleGrille = (this.dimGridCases*(dimPixelCase+1)+1);
       hauteurFenetre = tailleGrille*9/8-20;
       largeurFenetre = tailleGrille*7/4;
            
       this.setSize(largeurFenetre,hauteurFenetre);
       //this.setAlwaysOnTop(true);
       this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       
       //Nous allons maintenant dire à notre objet de se positionner au centre
       this.setLocation(0,0);                                      


       
        this.setLayout(new BorderLayout());       
        //this.getContentPane().add(new JButton("WEST"), BorderLayout.WEST);
        
        
        //CENTER
        maGrille = new JPanelGrid(dimGridCases, dimPixelCase, mesAgents, espace2d, onlyValeurChamps, presencePheromones);

        maGrille.setConeDeflection(false);
        
        int labelHauteur = (this.dimPixelCase+1)*dimGridCases+1;
        int labelLargeur = (this.dimPixelCase+1)*dimGridCases+1;

        this.getContentPane().add(maGrille, BorderLayout.CENTER);
        
        //SOUTH
        JPanel JPanelSouth = new JPanel();
        GridLayout GridLayoutSud = new GridLayout(1,5);
        JPanelSouth.setLayout(GridLayoutSud);
        
        JButton startJButton = new JButton("Start");
        
        startJButton.addMouseListener(new EcouteurStart(startJButton));

        JButton exitJButton = new JButton("Quitter");
        exitJButton.addMouseListener(new EcouteurStart(exitJButton));
        /*JButton notice8JButton = new JButton("notice 8");*/
        JPanelSouth.add(startJButton);
        JPanelSouth.add(exitJButton);
        /*JPanelSouth.add(notice8JButton);
        notice8JButton.addMouseListener(new EcouteurNotice8());*/
        
        /*JPanelSouth.add(new JButton("1"));
        JPanelSouth.add(new JButton("2"));        
        JPanelSouth.add(new JButton("3"));
        JPanelSouth.add(new JButton("4"));*/         
        
        
        this.getContentPane().add(JPanelSouth, BorderLayout.SOUTH);
        this.getContentPane().add(new JPanel(), BorderLayout.NORTH);
      
        
        /*JPanel pan = new JPanel();
	pan.setBackground(Color.blue);
        JPanel pan2 = new JPanel();
	pan2.setBackground(Color.red);		
		//On construit enfin notre séparateur
	split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, pan, pan2);*/
		
		//On le passe ensuite au contentPane de notre objet Fenetre
		//placé au centre pour qu'il utilise tout l'espace disponible

	//this.getContentPane().add(split, BorderLayout.EAST); 
        //this.getContentPane().add(new JPanelSide(), BorderLayout.EAST); 

	//this.getContentPane().add(split, BorderLayout.EAST);
        side = new JPanelSide(mesAgents, dimGridCases, dimPixelCase, espace2d);
        this.getContentPane().add(side, BorderLayout.EAST); 

             
        this.setTitle("Multi-Agent Interface");
        this.setVisible(true);
    }
    

    public void repaintGrille() {
        maGrille.repaint();         
    }
    
    public void reInit(int dimGridCases, Vector<Agent> mesAgents, Espace2D espace2d,boolean onlyValeurChamps, boolean presencePheromones){
        maGrille = new JPanelGrid(dimGridCases, dimPixelCase, mesAgents, espace2d, onlyValeurChamps, presencePheromones);

        maGrille.setConeDeflection(false);
        
        int labelHauteur = (this.dimPixelCase+1)*dimGridCases+1;
        int labelLargeur = (this.dimPixelCase+1)*dimGridCases+1;

        this.getContentPane().add(maGrille, BorderLayout.CENTER);
        side.setAgents(mesAgents);
    }

    public void setVisibleGrid(boolean visible) {
        this.maGrille.setVisible(visible);
    }
        
        
}

